home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / DELPHI / NWLIB.ZIP / DEMO.ZIP / NDS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-25  |  3.6 KB  |  143 lines

  1. unit Nds;
  2.  
  3. interface
  4.  
  5. uses 
  6.      SysUtils,
  7.      WinTypes, 
  8.      WinProcs, 
  9.      Classes, 
  10.      Graphics, 
  11.      Forms, 
  12.      dialogs,
  13.      Controls, 
  14.      Buttons,
  15.      StdCtrls, 
  16.      ExtCtrls, 
  17.      Nwtools, 
  18.      Nwnds, 
  19.      Nwlib;
  20.  
  21. type
  22.   TwinNDS = class(TForm)
  23.     cancelBtn: TBitBtn;
  24.     Bevel1: TBevel;
  25.     Label1: TLabel;
  26.     NDScontext: TEdit;
  27.     NWNDS1: TNWNDS;
  28.     NWTools1: TNWTools;
  29.     binderyContext: TEdit;
  30.     Label2: TLabel;
  31.     NWLib1: TNWLib;
  32.     serverDN: TEdit;
  33.     Label3: TLabel;
  34.     Label4: TLabel;
  35.     loginBtn: TButton;
  36.     logoutBtn: TButton;
  37.     root: TEdit;
  38.     Label5: TLabel;
  39.     myinfo: TMemo;
  40.     attachBtn: TButton;
  41.     procedure FormShow(Sender: TObject);
  42.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  43.     procedure loginBtnClick(Sender: TObject);
  44.     procedure logoutBtnClick(Sender: TObject);
  45.     procedure attachBtnClick(Sender: TObject);
  46.   private
  47.     { Private declarations }
  48.   public
  49.     { Public declarations }
  50.   end;
  51.  
  52. var
  53.   winNDS: TwinNDS;
  54.  
  55. implementation
  56.  
  57. {$R *.DFM}
  58.  
  59. var
  60.   contextHandle : TNWDSContextHandle ;
  61.  
  62. procedure TwinNDS.FormShow(Sender: TObject);
  63.   var
  64.     nserver     : TNWConnHandle    ;
  65.     attrRights  : TNWDSAttrRights  ;
  66.     entryRights : TNWDSEntryRights ;
  67.     smsRights   : TNWDSSMSRights   ;
  68.   begin
  69.     if ndsInit then
  70.       begin
  71.         contextHandle       := ndsGetContextHandle ;
  72.         binderyContext.text := ndsGetBinderyContextName(getPrimaryServerID) ;
  73.         serverDN.text       := ndsGetServerDN(getPrimaryServerID) ;
  74.         root.text           := ndsGetRootName(ndsWhoAmI) ;
  75.         ndscontext.text     := ndsGetContextName ;
  76.  
  77.         myInfo.lines.clear ;
  78.         myInfo.lines.add(ndsWhoAmI) ;
  79.         myInfo.lines.add(ndsAbbreviateName(whoAmI(0))) ;
  80.         myInfo.lines.add(ndsGetObjID(0,ndsWhoAmI)) ;
  81.       end
  82.     else
  83.       alertBox('Novell Directory Services Not Installed') ;
  84.   end;
  85.  
  86. procedure TwinNDS.FormClose(Sender: TObject; var Action: TCloseAction);
  87.   begin
  88.     { must shut down nds communications ... else memory leaks! }
  89.     ndsFreeContext(contextHandle) ;
  90.     ndsClose;
  91.   end;
  92.  
  93. procedure TwinNDS.loginBtnClick(Sender: TObject);
  94.   var
  95.     cpass,
  96.     cUserID,
  97.     contextName : string ;
  98.   begin
  99.     contextName := padR(ndsGetContextName,32,' ') ;
  100.     cUserID     := padR(ndsWhoAmI,32,' ') ;
  101.     cpass       := space(32) ;
  102.     if inputQuery('NDS Login','Type Context String:',contextName) and
  103.        inputQuery('NDS Login','Type Your Login ID:',cUserID) and
  104.        inputQuery('NDS Login','Type Your Password:',cpass) then
  105.       begin
  106.         if ndsPassCheck(contextName,cUserID,cpass) and     { in case already logged in, } 
  107.            ndsLogin(contextName,cUserID,cpass) then  { doesn't kill login on bad attempt}
  108.           begin
  109.             logoutBtn.enabled := True ;
  110.             okBox('Login OK!') ;
  111.           end
  112.         else
  113.           alertBox('Incorrect UserID/Password;;Try Again') ;
  114.       end;
  115.   end;
  116.  
  117. procedure TwinNDS.logoutBtnClick(Sender: TObject);
  118.   begin
  119.     if YesNoBox('Logging Out;;Are You Sure?') and
  120.        ndsLogout then
  121.       begin
  122.         logoutBtn.enabled := False ;
  123.         okBox('logged out!') ;
  124.       end
  125.     else
  126.       alertBox('You Are Still Logged In') ;
  127.   end;
  128.  
  129. procedure TwinNDS.attachBtnClick(Sender: TObject);
  130.   var
  131.     ctext : string ;
  132.   begin
  133.     ctext := getServerName(0) ;
  134.     if inputQuery('Attach to DS Server','Type Server Name:',ctext) then
  135.       if (ndsAttach(ctext) > 0) then
  136.         okbox(ctext + ';Attached and Authenticated Successfully') 
  137.       else
  138.         alertBox('Error Attaching to Server!') ;
  139.  
  140.   end;
  141.  
  142. end.
  143.